package com.example.leetdemo.process;

public class Solution801 {

    public int minSwap(int[] nums1, int[] nums2) {
        int count = nums1.length;
        int switchCount = 0;
        for (int i = 0; i < nums2.length - 1; i++) {
            if (i != 0 ) {
                if (nums1[i] < nums2[i -1] || nums2[i] < nums1[i - 1]) {
                    continue;
                }
            }
            if (nums1[i] > nums2[i + 1] || nums2[i] > nums1[i + 1]) {
                continue;
            }
            if (nums1[i] > nums1[i + 1] || nums2[i] > nums2[i + 1]) {
                int temp = nums1[i];
                nums1[i] = nums2[i];
                nums2[i] = temp;
                switchCount++;
            }
        }
        return  Math.min(count - switchCount, switchCount);
    }

    public static void main(String[] args) {
        Solution801 solution801 = new Solution801();
        System.err.println(solution801.minSwap(new int[] {0,3,5,8,9}, new int[]{2,1,4,6,9}));
    }
}
